package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.FileService;
import com.atguigu.spzx.model.vo.common.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@Tag(name = "文件管理模块")
@RequestMapping("/admin/system/file")
public class FileController {
    @Resource
    FileService fileService;
    @Operation(summary = "文件上传接口")
    @PostMapping("/upload")
    // MultipartFile: 多部件上传的一个文件(表单文件上传时 一个文件表单项代表一个部件)
    // file变量名 需要和前端提交的文件表单项name属性值一样
    //module 代表上传的文件保存到 minio桶内的哪个目录下
    public Result upload(MultipartFile file,String module){
//        int i = 1/0;
        //返回上传成功的文件路径
        String path = fileService.upload(file , module);
        return Result.ok().data(path);
    }


    @Operation(summary = "文件删除接口")
    @Parameter(name = "path" , description = "删除文件的全路径" ,
            in = ParameterIn.QUERY)
    @DeleteMapping("/remove")
    public Result remove(String path){
        fileService.remove(path);
        return Result.ok();
    }

}
